#include <stdio.h>

int a[14],b[14],k;

void dfs( int t, int count )
{
    int i;
    if ( count == 6 )
    {
        for ( i = 0; i < 6; i++)
        {
            printf("%d", a[ b[i] ]);
            if ( i != 5 ) printf(" ");
        }
        printf("\n");
    }
    else
    {
        for ( i = t + 1; i <= k - 6 + count; i++)
        {
            b[ count ] = i;
            dfs( i, count + 1 );
        }
    }
}
int main()
{
    int i;
    bool fl = 0;
    while ( scanf("%d", &k) != EOF )
    {
        if ( k == 0 ) break;
        if ( fl ) printf("\n");
        else fl = true;
        for ( i = 0; i < k; i++ )
            scanf("%d", &a[i]);
        for ( i = 0; i <= k - 6; i++ )
        {
            b[ 0 ] = i;
            dfs( i, 1 );
        }
    }
    return 0;
}
